//获取侧边栏
export function sidebarRoutes(routes) {
	let newRoutes = []
	routes.forEach((route) => {
		if (!(route.meta && route.meta.hidden)) {
			if (route.children) {
				route.children = sidebarRoutes(route.children)
				if (route.children.length == 0) {
					delete route.children
				}
				if (route.children.length == 1) {
					route = route.children[0]
				}
				newRoutes = [...newRoutes, route]
			} else {
				newRoutes = [...newRoutes, route]
			}
		}

	})
	return newRoutes
}

//判断路由是否配置有误
export function errorRoutes(routes) {
	var num = 0;
	(function aa(routes) {
		routes.forEach((route) => {
			if (!route.name) {
				num++
				console.error(`path:'${route.path}',name:'${route.name}'缺少name`)
			}
			if (route.meta && route.meta.fixld && route.meta.hidden) {
				num++
				console.error(`path:'${route.path}',name:'${route.name}'有误`)
			}
			if (route.children) {
				aa(route.children)
			}
		})
	}(routes))
	if (num) {
		throw new Error("路由配置错误")
	}
}
//获取固定页
export function fixedRoutes(routes) {
	var newRoutes = []
	routes.forEach((route) => {
		if (route.meta && route.meta.fixld && !route.redirect) {
			newRoutes = [...newRoutes, route]
		}
		if (route.children) {
			var list = fixedRoutes(route.children)
			newRoutes = [...newRoutes, ...list]
		}
	})
	return newRoutes
}
